Music Object Extension - Flash

  Contents

About This Extension

This extension is designed to make the process of sonifying Flash movies with Beatnik a little easier. The extension is currently quite simple, offering just two static methods. In time, as we learn more about the specific needs of Flash authors, this extension may be expanded to include other capabilities that benefit Beatnik sonification of Flash content.

For further information on sonifying Flash movies using Beatnik, consult the section Using Beatnik and Flash Together.

What's New in the Latest Version

There is a dedicated version history for this extension, where you will be able to find out about the new features and possible issues with the most recent version. The version history for this extension is independent of the version history for the core Music Object API.

Getting This Extension

To get the "music-object-x-flash.js" JavaScript file that implements this extension, simply right-click on this link (click-and-hold for Mac users). Then, from the menu that pops up, select the 'Save Link As...' or 'Save Target As...' option and save the file as "music-object-x-flash.js" into an appropriate folder of the local copy of your Web site.

In case you have problems saving the file using the above link, the "music-object-x-flash.js" file can also be found inside the documentation's "javascript" folder, along with the "music-object.js" file.

Dependencies

In order to use this extension, the following JavaScript file(s) must first be sourced in...

For more information on using extensions, consult the section About Music Object Extensions.

Reference

 Name   Short Description 
Static Methods
Music.embedFlashMovie Puts the necessary HTML code into the page to embed a Flash movie that is also "wired" to control Beatnik.
Music.wireFlashMovie Adds the necessary code to the page to enable a Flash movie to control Beatnik using the FSCommand.

Static Methods

 Music.embedFlashMovie

 
 CATEGORY   Static Method 
 MODULE   Music Object Extension - Flash 
 Min. Player Version   n/a 
 

The Music.embedFlashMovie static method puts the necessary HTML code into the page to embed a Flash movie that is also "wired" to control Beatnik.

SYNTAX    Music.embedFlashMovie ( FlashEmbedLineSTR )

The Music.embedFlashMovie static method goes even further than the Music.wireFlashMovie static method, in that it also generates the HTML code necessary to embed a Flash movie into a page in a way that is compatible with both Netscape Navigator and Microsoft Internet Explorer. If you are already familiar with Music Object's magicEmbed method, then using the Music.embedFlashMovie static method will be a snap. In principal, these two methods are much the same.

When using this method, all that is necessary is to specify the desired attribute values for the Flash movie using a String parameter. The syntax for the attribute name/value pairs is very similar to the format of an HTML EMBED tag, excepting that it is not necessary to specify the opening "<EMBED" and closing ">" in the String.

In the before-and-after example below, a typical Flash movie EMBED tag is transformed to its Music.embedFlashMovie equivalent...

BEFORE
<EMBED
   SRC="my-flash-movie.swf"
   WIDTH=600
   HEIGHT=400
   ALIGN=TOP
   NAME="myFlashMovie"
   QUALITY="high"
   BASE="http://www.mydomain.com"
   SWLIVECONNECT=TRUE
   MAYSCRIPT
   TYPE="application/x-shockwave-flash"
   PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"
>
AFTER (Using Music.embedFlashMovie)
<SCRIPT SRC="music-object.js"></SCRIPT>
<SCRIPT SRC="music-object-x-flash.js"></SCRIPT>

<SCRIPT LANGUAGE=JavaScript><!-- //

Music.embedFlashMovie (
   'SRC="my-flash-movie.swf" NAME="myFlashMovie" BASE="http://www.mydomain.com" ' +
   'WIDTH=600 HEIGHT=400 ALIGN=TOP QUALITY="high"'
);

// --></SCRIPT>

In the above example, the text that is highlighted in the "before" stage represents those attributes that should be specified in the Music.embedFlashMovie method, and you will see these same attributes highlighted in the "after" stage. Most importantly, you will notice that some of the attributes in the EMBED tag in the "before" stage have not been specified in the call to the Music.embedFlashMovie method in the "after" stage. That's because these attributes always have the same value for all Flash movies and the Music.embedFlashMovie method writes these attributes into the generated HTML EMBED tag automatically. This, of course, makes life a whole lot easier.

Now, we've deliberately kept our before-and-after example simple, not including the OBJECT tag that is necessary to achieve compatibility with Microsoft Internet Explorer. By looking at the expanded before-and-after example below that includes the OBJECT tag, you will get a better idea of just how much time the Music.embedFlashMovie method can save you...

BEFORE
<OBJECT
   ID="myFlashMovie"
   WIDTH=600
   HEIGHT=400
   ALIGN=TOP
   CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
   CODEBASE="http://active.macromedia.com/flash/cabs/swflash.cab"
>
   <PARAM NAME="movie" VALUE="my-flash-movie.swf">
   <PARAM NAME="quality" VALUE="high">
   <EMBED
      SRC="my-flash-movie.swf"
      WIDTH=600
      HEIGHT=400
      ALIGN=TOP
      NAME="myFlashMovie"
      QUALITY="high"
      BASE="http://www.mydomain.com"
      SWLIVECONNECT=TRUE
      MAYSCRIPT
      TYPE="application/x-shockwave-flash"
      PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"
   >
</OBJECT>
AFTER (Using Music.embedFlashMovie)
<SCRIPT SRC="music-object.js"></SCRIPT>
<SCRIPT SRC="music-object-x-flash.js"></SCRIPT>

<SCRIPT LANGUAGE=JavaScript><!-- //

Music.embedFlashMovie (
   'SRC="my-flash-movie.swf" NAME="myFlashMovie" BASE="http://www.mydomain.com" ' +
   'WIDTH=600 HEIGHT=400 ALIGN=TOP QUALITY="high"'
);

// --></SCRIPT>

You can see now that between the EMBED and OBJECT tags, there are quite a few attributes that you no longer need to specify when using the Music.embedFlashMovie method, specifically the SWLIVECONNECT, MAYSCRIPT, TYPE, and PLUGINSPAGE attributes for the EMBED tag, and the CLASSID and CODEBASE attributes for the OBJECT tag. Not having to specify these attributes simplifies things somewhat.

Another very important thing to notice is how the ID attribute and MOVIE parameter for the OBJECT tag are not specified when using Music.embedFlashMovie. This is because the method uses the value specified for the NAME attribute as the value for the ID attribute in the OBJECT tag HTML that is generated, and the value specified for the SRC attribute is used as the value for the MOVIE parameter in the OBJECT tag HTML that is generated. So, when using the Music.embedFlashMovie method it is only necessary to specify the Flash movie's source file location once using the SRC attribute, and it is only necessary to specify the Flash Player instance's name once using the NAME attribute.

Finally, if you are already familiar with the Music.wireFlashMovie static method, then let's take a look at a before-and-after example to see how the newer Music.embedFlashMovie can simplify your coding...

BEFORE (Using just Music.wireFlashMovie)
<HTML><HEAD><TITLE>Beatnik and Flash Template</TITLE></HEAD>
<BODY>

<SCRIPT SRC="correct-path-here/music-object.js"></SCRIPT>
<SCRIPT SRC="correct-path-here/music-object-x-flash.js"></SCRIPT>

<OBJECT
   ID="myFlashMovie"
   WIDTH=600
   HEIGHT=400
   ALIGN=TOP
   CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
   CODEBASE="http://active.macromedia.com/flash/cabs/swflash.cab"
>
   <PARAM NAME="movie" VALUE="my-flash-movie.swf">
   <PARAM NAME="quality" VALUE="high">
   <EMBED
      SRC="my-flash-movie.swf"
      WIDTH=600
      HEIGHT=400
      ALIGN=TOP
      NAME="myFlashMovie"
      QUALITY="high"
      BASE="http://www.mydomain.com"
      SWLIVECONNECT=TRUE
      MAYSCRIPT
      TYPE="application/x-shockwave-flash"
      PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"
   >
</OBJECT>

<SCRIPT LANGUAGE=JavaScript><!-- //

Music.wireFlashMovie ('myFlashMovie');
player1 = new Music ();
player1.magicEmbed ('SRC="my-music-file.rmf" WIDTH=0 HEIGHT=0 HIDDEN AUTOSTART=TRUE');

// --></SCRIPT>

</BODY></HTML>
AFTER (Using Music.embedFlashMovie)
<HTML><HEAD><TITLE>Beatnik and Flash Template</TITLE></HEAD>
<BODY>

<SCRIPT SRC="correct-path-here/music-object.js"></SCRIPT>
<SCRIPT SRC="correct-path-here/music-object-x-flash.js"></SCRIPT>

<SCRIPT LANGUAGE=JavaScript><!-- //

Music.embedFlashMovie (
   'SRC="my-flash-movie.swf" NAME="myFlashMovie" BASE="http://www.mydomain.com" ' +
   'WIDTH=600 HEIGHT=400 ALIGN=TOP QUALITY="high"'
);
player1 = new Music ();
player1.magicEmbed ('SRC="my-music-file.rmf" WIDTH=0 HEIGHT=0 HIDDEN AUTOSTART=TRUE');

// --></SCRIPT>

</BODY></HTML>

As you can see, not only has the number of places been reduced where you have to make sure values exactly match up, but the code using the Music.embedFlashMovie is simpler, cleaner, and easier to update.

 Music.wireFlashMovie

 
 CATEGORY   Static Method 
 MODULE   Music Object Extension - Flash 
 Min. Player Version   n/a 
 

The Music.wireFlashMovie static method adds the necessary code to the page to enable a Flash movie to control Beatnik using the FSCommand.

SYNTAX    Music.wireFlashMovie ( FlashInstanceNameSTR )

The Music.wireFlashMovie method makes it easier to wire Flash movies so that they can use the FSCommand action to control the Music Object API. Using this method can clean up your sonification code considerably and also help to prevent mistakes that cause the Flash-to-Beatnik wiring to break. Consider the following before-and-after example to see how the code is simplified by using this method...

BEFORE
<SCRIPT SRC="music-object.js"></SCRIPT>

<SCRIPT LANGUAGE="JavaScript"><!--

function myFlashMovie_DoFSCommand (command,args) {
   eval (command + ((command.indexOf ('(') == -1) ? ('(' + args + ')') : ''));
}

//--></SCRIPT>

<SCRIPT LANGUAGE="VBScript"><!--

Sub myFlashMovie_FSCommand (ByVal command, ByVal args)
        call myFlashMovie_DoFSCommand (command, args)
end sub

//--></SCRIPT>
AFTER (Using Music.wireFlashMovie)
<SCRIPT SRC="music-object.js"></SCRIPT>
<SCRIPT SRC="music-object-x-flash.js"></SCRIPT>

<SCRIPT LANGUAGE=JavaScript><!-- //

Music.wireFlashMovie ('myFlashMovie');

// --></SCRIPT>

It becomes clear, looking at the example, that using the wireFlashMovie method also reduces the number of occurrences of the name "myFlashMovie", thereby reducing the chances of human error occurring. Furthermore, because each individual Flash movie needs to have its own unique FSCommand wrapper code, cases where more than one Flash movie in the same page are to be sonified create an even more compelling reason to use this method for the savings it provides. Consider the following before-and-after example involving two Beatnik-sonified Flash movies...

BEFORE
<SCRIPT SRC="music-object.js"></SCRIPT>

<SCRIPT LANGUAGE="JavaScript"><!--

function myFlashMovie1_DoFSCommand (command,args) {
   eval (command + ((command.indexOf ('(') == -1) ? ('(' + args + ')') : ''));
}

function myFlashMovie2_DoFSCommand (command,args) {
   eval (command + ((command.indexOf ('(') == -1) ? ('(' + args + ')') : ''));
}

//--></SCRIPT>

<SCRIPT LANGUAGE="VBScript"><!--

Sub myFlashMovie1_FSCommand (ByVal command, ByVal args)
        call myFlashMovie1_DoFSCommand (command, args)
end sub

Sub myFlashMovie2_FSCommand (ByVal command, ByVal args)
        call myFlashMovie2_DoFSCommand (command, args)
end sub

//--></SCRIPT>
AFTER (Using Music.wireFlashMovie)
<SCRIPT SRC="music-object.js"></SCRIPT>
<SCRIPT SRC="music-object-x-flash.js"></SCRIPT>

<SCRIPT LANGUAGE=JavaScript><!-- //

Music.wireFlashMovie ('myFlashMovie1');
Music.wireFlashMovie ('myFlashMovie2');

// --></SCRIPT>

Now, examine the following Beatnik-Flash sonification template to see how this method is used in context...

Copy-and-Paste
<HTML><HEAD><TITLE>Beatnik and Flash Template</TITLE></HEAD>
<BODY>

<SCRIPT SRC="correct-path-here/music-object.js"></SCRIPT>
<SCRIPT SRC="correct-path-here/music-object-x-flash.js"></SCRIPT>

<OBJECT
   ID="myFlashMovie"
   WIDTH=600
   HEIGHT=400
   ALIGN=TOP
   CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
   CODEBASE="http://active.macromedia.com/flash/cabs/swflash.cab"
>
   <PARAM NAME="movie" VALUE="my-flash-movie.swf">
   <PARAM NAME="quality" VALUE="high">
   <EMBED
      SRC="my-flash-movie.swf"
      WIDTH=600
      HEIGHT=400
      ALIGN=TOP
      NAME="myFlashMovie"
      QUALITY="high"
      BASE="http://www.mydomain.com"
      SWLIVECONNECT=TRUE
      MAYSCRIPT
      TYPE="application/x-shockwave-flash"
      PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"
   >
</OBJECT>

<SCRIPT LANGUAGE=JavaScript><!-- //

Music.wireFlashMovie ('myFlashMovie');
player1 = new Music ();
player1.magicEmbed ('SRC="my-music-file.rmf" WIDTH=0 HEIGHT=0 HIDDEN AUTOSTART=TRUE');

// --></SCRIPT>

</BODY></HTML>

You can simplify your code even further by using the newer Music.embedFlashMovie static method.